//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.IO;
using OpenLS.Spreadsheet.Expressions;

namespace OpenLS.Spreadsheet.Formats.Biff.Tokens
{
    internal class NumberToken : FormulaToken
    {
        private double _value;

        public NumberToken(double value)
        {
            this._value = value;
        }

        public NumberToken()
        {
            
        }
        public override ushort GetLength(FormulaReadContextType formulaReadContextType)
        {
            return 8;
        }
        public override FormulaTokenId TokenId
        {
            get { return FormulaTokenId.Num; }
        }

        internal override void ReadContent(FormulaReadContext context)
        {
            _value = context.ReadDouble();
        }
        public override void WriteContent(FormulaWriteContext context)
        {
            context.Writer.Write((double)_value);
        }

        internal override Expression GetExpression(FormulaEvaluationContext context)
        {
            return new DoubleConstantExpression(_value.ToString(), _value);
        }
    }
}